package com.lagou.service.impl;

import com.lagou.service.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.Date;

@Service
public class EmailServiceImpl implements EmailService {

    @Value("${spring.mail.username}")
    private String email;

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public boolean sendEmail(String email, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("这是一封测试邮件");//设置邮件主题
        message.setFrom("1107029243@qq.com");//设置邮件发送者
        message.setTo(email);//设置邮件接收者，可以有多个接收者
//        message.setCc("37xxxxx37@qq.com");//设置邮件抄送人，可以有多个抄送人
//        message.setBcc("14xxxxx098@qq.com");//设置隐秘抄送人，可以有多个
        message.setSentDate(new Date());
        message.setText("验证码：" + code + "，10分钟内有效.");
        javaMailSender.send(message);
        return true;
    }

    @Override
    public String test() {
        return email;
    }
}
